<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_xyb2b_group',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['status']=array('0'=>'不显示','1'=>'显示');
	$return['isrecommand']=array('0'=>'不推荐','1'=>'推荐');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'分类管理'),
		),
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(			
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'category_id','title'=>'行云ID','type'=>'string'),	
		),'action'=>array(
			array('type'=>'post','op'=>'updatagoods','title'=>'同步商品'),
		),'batch'=>array(
			array('type'=>'post','url'=>'/group/updata/','title'=>'同步类目'),
		)),
		'search_one'=>array('name'=>'title','title'=>'商品类目名称','add'=>false),
	);
	$return['htmls']=$htmls;
	
	exi($return);
}
if($_RQ['op']=='updata'){
	$this->model('goods')->upcate();
	exi('同步类目成功！');
}
if($_RQ['op']=='updatagoods'){
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_xyb2b_group',array('id'=>$id));
	$this->model('goods')->updatagoods($item['category_id']);
	exi('同步商品成功！');
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_xyb2b_group',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	$return['status']=array('0'=>'不显示','1'=>'显示');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'分类设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'分类管理'),
		),
		'edit'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'category_id','title'=>'行云ID','type'=>'string'),			
			)
	);
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title'] ){
		exi('请填写标题','error');
	}
	$data=array_fields(array('title','paixu','category_id'),$postdata);
	$id=intval($postdata['id']);
	if($id){
				pdo_update('jy_xyb2b_group',$data,array('id'=>$id));
				exi('设置成功！','','/group/');
	}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				 $data['createtime']=time();
				pdo_insert('jy_xyb2b_group',$data);
				exi('添加成功！','','/group/');
	}
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_xyb2b_group',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_xyb2b_group',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>